package com.hjtech.user.presenter;

import com.apkfuns.logutils.LogUtils;
import com.hjtech.base.app.MyApp;
import com.hjtech.base.base.BasePresenterImpl;
import com.hjtech.base.retroft.exception.ExceptionHelper;
import com.hjtech.user.api.ApiService;
import com.hjtech.user.contact.UserContact;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/*
 * 项目名:    HjtechARouterFrame
 * 包名       com.hjtech.user.presenter
 * 文件名:    UserPresenter
 * 创建者:    ZJB
 * 创建时间:  2017/10/25 on 18:07
 * 描述:     TODO
 */

public class UserPresenter extends BasePresenterImpl<UserContact.view> implements UserContact.presenter {


    public UserPresenter(UserContact.view view) {
        super(view);

    }

    @Override
    public void getStr() {
        MyApp.getApplication().getRetrofit().create(ApiService.class)
                .getProvince()
                .subscribeOn(Schedulers.io())
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(@io.reactivex.annotations.NonNull Disposable disposable) throws Exception {
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(@NonNull String Str) throws Exception {
                        view.setStr(Str);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(@NonNull Throwable throwable) throws Exception {
                        LogUtils.e(ExceptionHelper.handleException(throwable));
                    }
                });
    }
}
